#include"stack.h"
#if 0
int main()
{
	ST st;
	STinit(&st);
	STpush(&st, 1);
	STpush(&st, 2);
	STpush(&st, 3);
	STpush(&st, 4);
	printf("%d\n", STtop(&st));
	STpop(&st);
	printf("%d\n", STtop(&st));
	STpop(&st);
	STpop(&st);
	STpop(&st);
	//STpop(&st);
	STdestroy(&st);
	return 0;
}
int main()
{
	ST st;
	STinit(&st);
	STpush(&st, 1);
	STpush(&st, 2);
	printf("%d ", STtop(&st));
	STpop(&st);
	STpush(&st, 3);
	STpush(&st, 4);
	while (!STempty(&st))
	{
		printf("%d ", STtop(&st));
		STpop(&st);
	}
	STdestroy(&st);
	return 0;
}
#endif
bool Isvalid(char* s)
{
	ST st;
	STinit(&st);
	while (*s)
	{
		if (*s == '(' || *s == '[' || *s == '{')
		{
			STpush(&st, *s);
		}
		else
		{
			if (STempty(&st))
			{
				STdestroy(&st);
				return false;
			}
			char top = STtop(&st);
			STpop(&st);
			if ((top == '(' && *s != ')')
				|| (top == '[' && *s != ']')
				|| (top == '{' && *s != '}'))
			{
				return false;
			}
		}
		++s;
	}
	bool ret = STempty(&st);
	STdestroy(&st);
	return ret;
}